﻿using System.Collections.Generic;
using AbstractBugTracker;

namespace JiraRest
{
    /// <summary>
    /// An in-memory form of the data required to create an autobug. Should only be used pre-creation
    /// </summary>
    public sealed class JiraBugDef : BugDef
    {
        private readonly Dictionary<string, object> m_DictionaryRepresentation;

        internal JiraBugDef(JiraConfig jiraConfig, JiraConnection connection, JiraBugRef cleanBugRef, Dictionary<string, object> dictionaryRepresentation)
            : base(cleanBugRef)
        {
            m_DictionaryRepresentation = dictionaryRepresentation;

            // create as an autobug
            Fields["issuetype"] = new { id = connection.GetIssueTypeId(jiraConfig.BugIssueTypeName) };
        }

        public Dictionary<string, object> DictionaryRepresentation
        {
            get { return m_DictionaryRepresentation; }
        }

        public Dictionary<string, object> Fields
        {
            get { return (Dictionary<string, object>) m_DictionaryRepresentation["fields"]; }
        }

        public void CleanAndSetTitle(string value)
        {
            Fields["summary"] = JiraUtils.Clean(value, false);
        }

        public void CleanAndSetDescription(string value)
        {
            Fields["description"] = JiraUtils.Clean(value, true);
        }
    }
}
